﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;

namespace ChartOO
{
    class ViewModel: INotifyPropertyChanged
    {
        int i;

        public ViewModel()
        {
            this.RefreshCommand = new MyCommand(this.Refresh);

            this.List = new List<Model> {
                    new Model { Key="Joey",Value= 10,Proportion = 0.1,Color = Color.FromRgb(34,44,1)},
                    new Model { Key="Ross",Value= 20,Proportion = 0.2,Color = Color.FromRgb(10,10,99)},
                    new Model { Key="Monic",Value= 30,Proportion = 0.5,Color = Color.FromRgb(200,100,100)},
                    new Model { Key="Phebe",Value= 40,Proportion = 0.1,Color = Color.FromRgb(11,99,11)},
                    new Model { Key="Rachel",Value= 50,Proportion = 0.2,Color = Color.FromRgb(21,55,21)},
                    new Model { Key="Chandler",Value= 60,Proportion = 0.8,Color = Color.FromRgb(121,11,221)},
                    new Model { Key="Fuck",Value= 60,Proportion = 0.8,Color = Color.FromRgb(121,121,221)},
                    new Model { Key="WomanGod",Value= 60,Proportion = 0.8,Color = Color.FromRgb(12,1,221)}
                };
        }

        private void Refresh()
        {
            if (++i % 2 == 0)
            {
                this.List = new List<Model> {
                    new Model { Key="Joey",Value= 50,Proportion = 0.1,Color = Color.FromRgb(1,22,1)},
                    new Model { Key="Ross",Value= 20,Proportion = 0.2,Color = Color.FromRgb(10,234,10)},
                    new Model { Key="Monic",Value= 40,Proportion = 0.5,Color = Color.FromRgb(100,234,234)},
                    new Model { Key="Phebe",Value= 50,Proportion = 0.1,Color = Color.FromRgb(11,234,11)},
                    new Model { Key="Rachel",Value= 20,Proportion = 0.2,Color = Color.FromRgb(234,21,21)},
                    new Model { Key="Chandler",Value= 50,Proportion = 0.8,Color = Color.FromRgb(1,211,221)},
                    new Model { Key="Hot",Value= 50,Proportion = 0.8,Color = Color.FromRgb(234,1,221)},
                    new Model { Key="Fuck",Value= 50,Proportion = 0.8,Color = Color.FromRgb(234,211,1)},
                    new Model { Key="Holiday",Value= 50,Proportion = 0.8,Color = Color.FromRgb(234,2,2)},
                    new Model { Key="Birthday",Value= 50,Proportion = 0.8,Color = Color.FromRgb(12,12,221)},
                };
            }
            else
            {
                this.List = new List<Model> {
                    new Model { Key="Joey",Value= 10,Proportion = 0.1,Color = Color.FromRgb(111,44,1)},
                    new Model { Key="Ross",Value= 20,Proportion = 0.2,Color = Color.FromRgb(111,10,99)},
                    new Model { Key="Monic",Value= 30,Proportion = 0.5,Color = Color.FromRgb(200,100,100)},
                    new Model { Key="Phebe",Value= 40,Proportion = 0.1,Color = Color.FromRgb(11,99,11)},
                    new Model { Key="Rachel",Value= 50,Proportion = 0.2,Color = Color.FromRgb(111,55,21)},
                    new Model { Key="Chandler",Value= 60,Proportion = 0.8,Color = Color.FromRgb(121,11,221)},
                    new Model { Key="Fuck",Value= 60,Proportion = 0.8,Color = Color.FromRgb(121,121,221)},
                    new Model { Key="WomanGod",Value= 60,Proportion = 0.8,Color = Color.FromRgb(111,1,221)},
                    new Model { Key="ManGod",Value= 60,Proportion = 0.8,Color = Color.FromRgb(12,1,221)}
                };
            }

        }

        private List<Model> _list;

        public List<Model> List
        {
            get { return _list; }
            set
            {
                _list = value;
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs("List"));
                }
            }
        }


        public ICommand RefreshCommand { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

    }
}
